<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>博客发布</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css">
    <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css">
</head>
<body>
    <!--导航-->
    <nav th:replace="admin/_fragments :: menu(2)" class="ui  inverted attached segment m-padded-tb-mini m-shadow-small">
        <div class="ui container">
            <div class="ui inverted secondary stackable menu">
                <h2 class="ui blue header item">鄭氏博客管理后台</h2>
                <a href="#" class="active m-item item m-mobile-hide"><i class="ui red  home icon"></i>博客管理</a>
                <a href="#" class=" m-item item m-mobile-hide"><i class="green sitemap icon"></i>分类管理</a>
                <a href="#" class="m-item item m-mobile-hide"><i class="purple tags icon"></i>标签管理</a>
                <div class="right menu m-item m-mobile-hide">
                    <div class="ui dropdown item">
                        <div class="text">
                            <img src="https://picsum.photos/id/237/100/100" alt="" class="ui acatar image">
                            鄭成功
                        </div>
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <a href="" class="item">个人信息</a>
                            <a href="" class="item">修改密码</a>
                            <a href="" class="item">注销</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <a href="" class="ui menu toggle black icon button m-right-top m-mobile-show"> <i class="sidebar icon"></i></a>
    </nav>
    <!--二级导航-->
    <div class="ui attached inverted pointing menu">
        <div class="ui container">
            <div class="left menu">
                <div class="active item pink" th:text="*{id}==null ? '新增博文' : '修改博文'"><i class="plus purple icon"></i>发布博文</div>
                <a th:href="@{/admin/blogs}" class="teal item">博文列表</a>
            </div>
        </div>
    </div>
    <!--中间部分-->
    <div class=" m-padded-tb-large">
        <div class="ui container">
            <form id="blog-form" th:action="@{/admin/blogs}" th:object="${blog}" class="ui form" method="post">
                <input type="hidden" name="published">
                <input type="hidden" name="id" th:value="*{id}">
                <div class="required field">
                    <div class="ui left labeled  input">
                        <div class="ui selection compact pink basic dropdown label">
                            <input type="hidden" value="原创" name="flag" th:value="*{flag}!=null ? *{flag} :'原创'">
                            <i class="dropdown icon"></i>
                            <div class="text">原创</div>
                            <div class="menu">
                                <div class="item" data-value="原创">原创</div>
                                <div class="item" data-value="转载">转载</div>
                                <div class="item" data-value="翻译">翻译</div>
                            </div>
                        </div>
                        <input type="text" name="title" th:value="*{title}" placeholder="请输入标题......">
                    </div>
                </div>
                <!--博客正文-->
                <div class="required field">
                    <div id="md-content" style="z-index: 1 !important;">
                        <textarea placeholder="博客内容" name="content" th:text="*{content}" style="display: none"></textarea>
                    </div>
                </div>

                <div class="two fields">
                    <div class="required field">
                        <div class="ui left labeled action input">
                            <label class="ui  green compact basic label"><i class=" sitemap icon"></i>博文分类</label>
                            <div class="ui fluid selection dropdown">
                                <input type="hidden" name="type.id" th:value="*{type}!=null ? *{type.id}">
                                <i class="dropdown icon"></i>
                                <div class="default text">请选择分类......</div>
                                <div class="menu">
                                    <div class="item" th:each="type : ${types}" th:data-value="${type.id}" th:text="${type.name}">错误日志</div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui left labeled action input">
                            <label class="ui compact purple basic label"><i class=" tags icon"></i>博文标签</label>
                            <div class="ui fluid selection multiple search dropdown">
                                <input type="hidden" name="tagIds" th:value="*{tagIds}">
                                <i class="dropdown icon"></i>
                                <div class="default text">请选择标签......</div>
                                <div class="menu">
                                    <div th:each="tag : ${tags}"  th:data-value="${tag.id}" th:text="${tag.name}" class="item">MYSQL</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="required field">
                    <div class="ui left labeled input">
                        <label class="ui yellow basic label"><i class=" image icon"></i>首图</label>
                        <input type="text" th:value="*{firstPicture}" name="firstPicture" placeholder="请输入首图引用地址......">
                    </div>
                </div>


                <div class="required field">
                    <textarea name="description" th:text="*{description}" placeholder="请输入博客描述......" maxlength="199"></textarea>
                </div>

                <div class="inline fields">
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="recommend" th:checked="*{recommend}" name="recommend" checked class="hidden">
                            <label for="recommend">推荐</label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="shareStatement" th:checked="*{shareStatement}" name="shareStatement" class="hidden">
                            <label for="shareStatement">转载声明</label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="appreciation" th:checked="*{appreciation}" name="appreciation" class="hidden">
                            <label for="appreciation">打赏</label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="commentabled" th:checked="*{commentabled}" name="commentabled" class="hidden">
                            <label for="commentabled">评论</label>
                        </div>
                    </div>
                </div>

                <div class="ui error message"></div>

                <div class="ui right aligned container">
                    <button class="ui button" type="button" onclick="window.history.go(-1)">返回</button>
                    <button type="button" id="save-btn" class="ui black button">保存</button>
                    <button type="button" id="publish-btn" class="ui green button">发布</button>
                </div>
            </form>
        </div>
    </div>
    </div>
    <!--底部footer-->
    <!--底部footer-->
    <!--/*/<th:block th:replace="admin/_fragments :: script">/*/-->
    <script src="../static/js/jquery-3.6.0.min.js" th:src="@{/js/jquery-3.6.0.min.js}"></script>
    <script src="../static/js/semantic.min.js" th:src="@{/js/semantic.min.js}"></script>
    <script src="../../static/lib/editormd/editormd.js" th:src="@{/lib/editormd/editormd.js}"></script>
    <!--/*/</th:block>/*/-->
<script>
    //初始化Markdown编辑器
    var contentEditor;
    $(function () {
       contentEditor = editormd("md-content",{
           placeholder:'欢迎使用鄭氏博客Markdown编辑，左边编写，右边预览',  //默认显示的文字，这里就不解释了
           width: "100%",
           height: 600,
           //theme: "dark",//工具栏主题
           //previewTheme: "dark",//预览主题
           editorTheme: "pastel-on-dark",//编辑主题
           saveHTMLToTextarea: true,
           emoji: true,
           taskList: true,
           tocm: true,         // Using [TOCM]
           tex: true,                   // 开启科学公式TeX语言支持，默认关闭
           flowChart: true,             // 开启流程图支持，默认关闭
           sequenceDiagram: true,       // 开启时序/序列图支持，默认关闭,
           toolbarIcons : function() {  //自定义工具栏，后面有详细介绍
               return editormd.toolbarModes['full']; // full, simple, mini
           },
           syncScrolling: "single",
           path : "/lib/editormd/lib/", //依赖lib文件夹路径
           imageUpload: true,	//开启本地图片上传
           imageFormats: ["jpg", "jpeg", "gif", "png"],	//设置上传图片的格式
           imageUploadURL: "/admin/blogs/imgUpdate"		//上传图片请求路径
       });
    });
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
        return false;
    });
    $('.ui.dropdown').dropdown({
        on : 'hover'
    });

    //保存博文
    $('#save-btn').click(function () {
        $('[name="published"]').val(false);
        $('#blog-form').submit();
    });
    //发布博文
    $('#publish-btn').click(function () {
        $('[name="published"]').val(true);
        $('#blog-form').submit();
    });

    $('.ui.form').form({
       fields : {
           title : {
               identifier : 'title',
               rules : [{
                   type : 'empty',
                   prompt : '标题：请输入博文标题'
               }]
           },
           type : {
               identifier : 'type.id',
               rules : [{
                   type : 'empty',
                   prompt : '分类：请选择博文分类'
               }]
           },
           content : {
                identifier : 'content',
                    rules : [{
                    type : 'empty',
                    prompt : '内容：请输入博客内容'
                }]
            },
           firstPicture : {
               identifier : 'firstPicture',
               rules : [{
                   type : 'empty',
                   prompt : '博文首图：请输入博文首图地址'
               }]
           },
           description : {
               identifier : 'description',
               rules : [{
                   type : 'empty',
                   prompt : '描述：请输入博文描述'
               }]
           }

       },
        inline : true,
        on     : 'blur'
    });
</script>
</body>
</html>